<template>
    <view>
		<view class="apilist">
		    <view class="leftap">
		        <image src="../../static/img/ind0.png"></image>
		        <view class="nametpye">欧易</view>
		    </view>
		    <view class="poinbtn" @click="actiosheetokex">···</view>
		</view>
        <view class="apilist">
            <view class="leftap">
                <image src="../../static/img/ind2.png"></image>
                <view class="nametpye">火币</view>
            </view>
            <view class="poinbtn" @click="actiosheethuobi">···</view>
        </view>
        <view class="apilist">
            <view class="leftap">
                <image src="../../static/img/ind1.png"></image>
                <view class="nametpye">币安</view>
            </view>
            <view class="poinbtn" @click="actiosheetbian">···</view>
        </view>
        <!-- <wyb-popup ref="popup" type="center" height="390" width="600" radius="10">
            <view style="border-radius: 10px;">
                <view class="ncs">输入短信验证码</view>
                <view class="uicnm">
                    验证码已发送至
                    <text>{{isTeloremil}}</text>
                </view>
                <input class="csqb" v-model="cnayamz" type="number" placeholder="请输入验证码" />
                <view class="subyzmbtn">
                    <text class="nmzls" @tap="getPhonecode">{{codeBtn.codeText}}</text>
                    <text class="cnmde" @click="okBtnfn">确定</text>
                </view>
            </view>
        </wyb-popup> -->
		<!-- <wyb-popup ref="popupBinance" type="center" height="390" width="600" radius="10">
		    <view style="border-radius: 10px;">
		        <view class="ncs">输入短信验证码</view>
		        <view class="uicnm">
		            验证码已发送至
		            <text>{{isTeloremil}}</text>
		        </view>
		        <input class="csqb" v-model="cnayamz" type="number" placeholder="请输入验证码" />
		        <view class="subyzmbtn">
		            <text class="nmzls" @tap="getPhonecode">{{codeBtn.codeText}}</text>
		            <text class="cnmde" @click="okBtnfnExchange">确定</text>
		        </view>
		    </view>
		</wyb-popup> -->
    </view>
</template>

<script>
    let uinfo;
    import request from "../../untils/request.js";
    import wybPopup from '@/components/wyb-popup/wyb-popup.vue';

    export default {
        components: {
            wybPopup
        },
        data() {
            return {
                isTeloremil: '',
                cnayamz: '',
                codeBtn: {
                    codeTime: 60,
                    codeText: "获取验证码",
                    codeStatus: true,
                },
            }
        },
        onLoad() {

            uinfo = uni.getStorageSync('userInfo');
            if (uinfo.userLoginInfo.mobile != null) {
                this.isTeloremil = uinfo.userLoginInfo.mobile;
            } else {
                this.isTeloremil = uinfo.userLoginInfo.email;
            }

        },

        methods: {
            //欧易
            actiosheetokex() {
                let _this = this;
                uni.showActionSheet({
                    itemList: ['设置API Key', '删除API Key'],
                    success: function(res) {
                        //console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
                        if (res.tapIndex == 0) {
                            uni.navigateTo({
                                url: '../importapi/importapiokex'
                            });
                        }
                        if (res.tapIndex == 1) {
                            request.postMember('/user/info/queryUserInfo', {
                                userId: uinfo.userId,
                            }).then(res => {
                                if (res.code == '200') {
                                    //是否绑定手机号mobile  null未绑定
                                    if (res.data.mobile == null) {
                                        uni.showToast({
                                            icon: "none",
                                            title: '请先设置支付密码',
                                        })
                                        uni.navigateTo({
                                            url: '/pages/bindtel/bindtel',
                                        })
                                    } else {
                                        console.log('已绑定')
                                        uni.showModal({
                                            title: '从超级量化正式版上面删除API',
                                            content: '如果你把你的API Key从我们的服务器删除，你在此交易所的所以策略都将撤销，你确认要删除吗？',
                                            confirmText: '确认',
                                            confirmColor: '#7F6AC3',
                                            success: function(res) {
                                                if (res.confirm) {
                                                    console.log('用户点击确定');
                                                    // _this.$refs.popup.show();
                                                    // _this.getPhonecode();
                                                    _this.okBtnfnExchange(0)
                                                } else if (res.cancel) {
                                                    console.log('用户点击取消');
                                                }
                                            }
                                        });

                                    }
                                }
                            })
                        }
                    },
                    fail: function(res) {
                        console.log(res.errMsg);
                    }
                });
            },
            //火币
            actiosheethuobi() {
                let _this = this;
                uni.showActionSheet({
                    itemList: ['设置API Key', '删除API Key'],
                    success: function(res) {
                        //console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
                        if (res.tapIndex == 0) {
                            uni.navigateTo({
                                url: '../importapi/importapihuobi'
                            });
                        }
                        if (res.tapIndex == 1) {
                            request.postMember('/user/info/queryUserInfo', {
                                userId: uinfo.userId,
                            }).then(res => {
                                if (res.code == '200') {
                                    //是否绑定手机号mobile  null未绑定
                                    if (res.data.mobile == null) {
                                        uni.showToast({
                                            icon: "none",
                                            title: '请先设置支付密码',
                                        })
                                        uni.navigateTo({
                                            url: '/pages/bindtel/bindtel',
                                        })
                                    } else {
                                        console.log('已绑定')
                                        uni.showModal({
                                            title: '从超级量化正式版上面删除API',
                                            content: '如果你把你的API Key从我们的服务器删除，你在此交易所的所以策略都将撤销，你确认要删除吗？',
                                            confirmText: '确认',
                                            confirmColor: '#7F6AC3',
                                            success: function(res) {
                                                if (res.confirm) {
                                                    console.log('用户点击确定');
                                                    // _this.$refs.popup.show();
                                                    // _this.getPhonecode();
                                                    _this.okBtnfnExchange(1)
                                                } else if (res.cancel) {
                                                    console.log('用户点击取消');
                                                }
                                            }
                                        });

                                    }
                                }
                            })
                        }
                    },
                    fail: function(res) {
                        console.log(res.errMsg);
                    }
                });
            },
            //弹框确定
            okBtnfn() {
                if (this.cnayamz == '') {
                    return uni.showToast({
                        icon: "none",
                        title: '请输入验证码',
                    });
                }
                request.postMember('/user/exchange/huobi/huobiUnbind', {
                    accountId: this.isTeloremil, //账户id ,
                    businessType: '4', //验证码类型 1.注册 2.登陆 3.账号安全,4.解绑交易所账户 ,
                    userId: uinfo.userId, //用户id ,
                    verifyCode: this.cnayamz //,验证码
                }).then(res => {
                    if (res.code == '200') {
                        this.cnayamz = '';
                        this.$refs.popup.hide();
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                    } else {
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                    }
                })
            },
			//弹框确定
			okBtnfnExchange(exchangeType) {
			    /* if (this.cnayamz == '') {
			        return uni.showToast({
			            icon: "none",
			            title: '请输入验证码',
			        });
			    } */
				uni.showLoading({
				    mask:true
				});
				let unBindUrl = ''
				if(exchangeType == 0){
					unBindUrl = '/user/exchange/okex/okexUnbind'
				}else if(exchangeType == 1){
					unBindUrl = '/user/exchange/huobi/huobiUnbind'
				}else if(exchangeType == 2){
					unBindUrl = '/user/exchange/binance/binanceUnbind'
				}
				
				this.cnayamz = '1234'
			    request.postMember(unBindUrl, {
			        accountId: this.isTeloremil, //账户id ,
			        businessType: '4', //验证码类型 1.注册 2.登陆 3.账号安全,4.解绑交易所账户 ,
			        userId: uinfo.userId, //用户id ,
			        verifyCode: this.cnayamz //,验证码
			    }).then(res => {
			        console.log(res);
			        if (res.code == '200') {
			            this.cnayamz = '';
						uni.hideLoading();
						uni.showToast({
						    icon: "none",
						    title: '删除成功',
							duration: 2000
						});
			            this.$refs.popup.hide();
			        } else {
			            uni.hideLoading();
			            uni.showToast({
			                icon: "none",
			                title: res.message,
			            });
			        }
			    })
			},
            //获取验证码
            getPhonecode() {
                //0手机号，1邮箱
                let telEmail = '0';
                if (uinfo.userLoginInfo.email == null) {
                    telEmail = '0';
                } else {
                    telEmail = '1';
                }
                if (this.codeBtn.codeStatus) {
                    this.codeBtn.codeStatus = false;
                    let timerId = setInterval(() => {
                        let codetime = this.codeBtn.codeTime;
                        codetime--;
                        this.codeBtn.codeTime = codetime;
                        this.codeBtn.codeText = "剩余" + codetime + "秒";
                        if (codetime < 1) {
                            clearInterval(timerId);
                            this.codeBtn.codeText = "重新获取";
                            this.codeBtn.codeTime = 60;
                            this.codeBtn.codeStatus = true;
                        }
                    }, 1000);

                    //1.注册 2.登陆 3.账号安全 4.解绑账户
                    request.postMember('/user/login/sendVerifiyCode', {
                        accountNumber: this.isTeloremil,
                        businessType: '4',
                        accountType: telEmail
                    }).then(res => {
                        if (res.code == "200") {
                            uni.showToast({
                                icon: "none",
                                title: '发送成功',
                            });
                        } else {
                            uni.showToast({
                                icon: "none",
                                title: res.message,
                            });
                        }
                    })
                }
            },
            actiosheetbian() {
                let _this = this;
                uni.showActionSheet({
                    itemList: ['设置API Key', '删除API Key'],
                    success: function(res) {
                        //console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
                        if (res.tapIndex == 0) {
                            uni.navigateTo({
                                url: '../importapi/importapibinance'
                            });
                        }
                        if (res.tapIndex == 1) {
                            request.postMember('/user/info/queryUserInfo', {
                                userId: uinfo.userId,
                            }).then(res => {
                                if (res.code == '200') {
                                    //是否绑定手机号mobile  null未绑定
									res.data.mobile = ''
                                    if (res.data.mobile == null) {
                                        uni.showToast({
                                            icon: "none",
                                            title: '请先设置支付密码',
                                        })
                                        uni.navigateTo({
                                            url: '/pages/bindtel/bindtel',
                                        })
                                    } else {
                                        console.log('已绑定')
                                        uni.showModal({
                                            title: '是否删除API',
                                            content: '如果你把你的API Key从我们的服务器删除，你在此交易所的所以策略都将撤销，你确认要删除吗？',
                                            confirmText: '确认',
                                            confirmColor: '#7F6AC3',
                                            success: function(res) {
                                                if (res.confirm) {
                                                    console.log('用户点击确定');
                                                    // _this.$refs.popupBinance.show();
                                                    // _this.getPhonecode();
													_this.okBtnfnExchange(2)
                                                } else if (res.cancel) {
                                                    console.log('用户点击取消');
                                                }
                                            }
                                        });
                                    }
                                }
                            })
                        }
                    },
                    fail: function(res) {
                        console.log(res.errMsg);
                    }
                });
            },
        }
    }
</script>

<style>
    .apilist {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: 0 10px;
        padding: 20px 0 20px 0;
        border-bottom: 1px solid #EBEBEB;
    }

    .apilist .leftap {
        display: flex;
        align-items: center;
    }

    .apilist image {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        margin: 0 10px 0 0;
    }

    .apilist .nametpye {
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #333333;
    }

    .apilist .poinbtn {
        color: #333333;
        font-size: 20px;
        font-weight: bold;
    }

    .ncs {
        text-align: center;
        padding: 10px 0 10px 0;
        font-size: 20px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #333333;
    }

    .uicnm {
        text-align: center;
        color: #ADB0BB;
        font-size: 14px;
    }

    .uicnm text {
        text-align: center;
        color: #7F6AC3;
        font-size: 14px;
    }

    .csqb {
        text-align: center;
        border-bottom: 1px solid #7F6AC3;
        width: 300rpx;
        height: 60rpx;
        margin: 20px auto 60rpx;
    }

    .subyzmbtn {
        text-align: center;
    }

    .subyzmbtn .nmzls {
        display: inline-block;
        background: #7F6AC3;
        padding: 10rpx 0px;
        width: 200rpx;
        color: #FFFFFF;
        font-size: 26rpx;
        border-radius: 10px;
    }

    .subyzmbtn .cnmde {
        display: inline-block;
        background: #7F6AC3;
        padding: 10rpx 0px;
        width: 200rpx;
        margin: 0 0 0 10px;
        color: #FFFFFF;
        font-size: 26rpx;
        border-radius: 18rpx;
    }
</style>
